﻿@using Model.Database
@model Model.Database.UserInfo
@{
    if (Model != null)
    {
        string powerId = ViewData["powerId"] as string;
        List<Power> powerList = new List<Power>();

        foreach (var role in Model.Roles)
        {
            powerList.AddRange(role.Powers.ToList()); ;
        }
        foreach (var department in Model.Departments)
        {
            foreach (var role in department.Roles)
            {
                powerList.AddRange(role.Powers.ToList());
            }
        }
        HashSet<Power> powerSet = new HashSet<Power>(powerList);
        powerList.Clear();
        powerList = powerSet.ToList();
        foreach (var powerBtn in powerList.Where(a => a.ParentId == powerId).OrderBy(a=>a.Sort))//菜单对应的按钮权限(控制CRUD按钮的样式)
        {
            string powerBtnName = powerBtn.PowerName;
            string url = powerBtn.Url;
            int sort = powerBtn.Sort.Value;

            if (powerBtnName.Contains("增加")|| powerBtnName.Contains("新增"))
            {
                <a id="add" url="@url" class="btn btn-primary radius" href="javascript:;"><i class="Hui-iconfont">&#xe600;</i> @powerBtnName</a>
                continue;
            }
            if (powerBtnName.Contains("删除"))
            {
                switch (powerBtnName)
                {
                    case "删除超过7天的日志":
                        {
                            <a id="delete7DayLog" url="@url" class="btn btn-danger radius" href="javascript:;"><i class="Hui-iconfont">&#xe6e2;</i> @powerBtnName</a>
                            break;
                        }
                    case "删除超过15天的日志":
                        {
                            <a id="delete15DayLog" url="@url" class="btn btn-danger radius" href="javascript:;"><i class="Hui-iconfont">&#xe6e2;</i> @powerBtnName</a>
                            break;
                        }
                    default:
                        {
                            <a id="delete" url="@url" class="btn btn-danger radius" href="javascript:;"><i class="Hui-iconfont">&#xe6e2;</i> @powerBtnName</a>
                            break;
                        }
                }
                continue;
            }
            if (powerBtnName.Contains("修改") || powerBtnName.Contains("编辑"))
            {
                <a id="edit" url="@url" class="btn btn-warning radius" href="javascript:;"><i class="Hui-iconfont">&#xe6df;</i> @powerBtnName</a>
                continue;
            }
            if (powerBtnName.Contains("查看")|| powerBtnName.Contains("详情"))
            {
                <a id="view" url="@url" class="btn btn-success radius" href="javascript:;"><i class="Hui-iconfont">&#xe725;</i> @powerBtnName</a>
                continue;
            }
            <a id="btn@{@sort}" url="@powerBtn.Url" class="btn btn-secondary radius" href="javascript:;"> @powerBtnName</a>
        }
    }
}